package com.maigao.api.controller;

import com.maigao.api.interceptors.identify.Identify;
import com.maigao.entity.ResultJson;
import com.maigao.entity.form.AddTakeOffRecordForm;
import com.maigao.entity.vo.TakeOffRecordVO;
import com.maigao.service.TakeOffRecordService;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: maigao
 * @description:
 * @author: yongza
 * @create: 2024-10-23 22:54
 **/
@RestController
@RequestMapping(value = "/takeOff")
public class TakeOffRecordController {

    @Autowired
    private TakeOffRecordService takeOffRecordService;

    @Identify
    @ResponseBody
    @RequestMapping("add")
    public ResultJson addClassRecord(AddTakeOffRecordForm addTakeOffRecordForm) {
        Pair<Boolean, String> addResult = takeOffRecordService.addTakeOff(addTakeOffRecordForm);
        if (addResult.getLeft()) {
            return ResultJson.success("");
        }
        return ResultJson.fail(addResult.getRight());
    }

    @Identify
    @ResponseBody
    @RequestMapping("revoke")
    public ResultJson revoke(@RequestParam Integer recordId) {
        Pair<Boolean, String> revokeResult = takeOffRecordService.revoke(recordId);
        if (revokeResult.getLeft()) {
            return ResultJson.success("");
        }
        return ResultJson.fail(revokeResult.getRight());
    }

    @Identify
    @ResponseBody
    @RequestMapping("audit")
    public ResultJson audit(@RequestParam Integer recordId, @RequestParam Integer auditStatus, String reason) {
        Pair<Boolean, String> revokeResult = takeOffRecordService.audit(recordId, auditStatus, reason);
        if (revokeResult.getLeft()) {
            return ResultJson.success("");
        }
        return ResultJson.fail(revokeResult.getRight());
    }

    /**
     * 学生端使用, 根据传入时间范围查询请假单列表
     *
     * @param fromTime
     * @param endTime
     * @return
     */
    @Identify
    @ResponseBody
    @RequestMapping("findStudentTakeOff")
    public ResultJson findStudentTakeOffRecord(@RequestParam String fromTime, @RequestParam String endTime) {
        Triple<Boolean, String, List<TakeOffRecordVO>> findResult = takeOffRecordService.findStudentTakeOffRecord(fromTime, endTime);
        if (findResult.getLeft()) {
            return ResultJson.success(findResult.getRight());
        }
        return ResultJson.fail(findResult.getMiddle());
    }

    @Identify
    @ResponseBody
    @RequestMapping("findCoachNeedAuditTakeOff")
    public ResultJson findCoachNeedAuditTakeOff() {
        Triple<Boolean, String, List<TakeOffRecordVO>> findResult = takeOffRecordService.findCoachNeedAuditTakeOffRecord();
        if (findResult.getLeft()) {
            return ResultJson.success(findResult.getRight());
        }
        return ResultJson.fail(findResult.getMiddle());
    }

    @Identify
    @ResponseBody
    @RequestMapping("findAdminNeedAuditTakeOff")
    public ResultJson findAdminNeedAuditTakeOff() {
        Triple<Boolean, String, List<TakeOffRecordVO>> findResult = takeOffRecordService.findAdminNeedAuditTakeOffRecord();
        if (findResult.getLeft()) {
            return ResultJson.success(findResult.getRight());
        }
        return ResultJson.fail(findResult.getMiddle());
    }

    /*@ResponseBody
    @RequestMapping("findByApproveUserUid")
    public ResultJson findByApproveUserUid(@RequestParam Integer approveUserUid) {

    }*/

}
